<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:conv="clr-namespace:QuickZip.Converters"            
    xmlns:local="clr-namespace:QuickZip.UserControls"            
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    xmlns:lc="clr-namespace:LoadingControl.Control"
    xmlns:ce="clr-namespace:CircularAnimations.Examples"
    >

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Brushes.xaml" />
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Geometry.xaml" />
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Converters.xaml" />
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Templates.xaml" />
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Styles.xaml" />
    </ResourceDictionary.MergedDictionaries>    

    <Style x:Key="{x:Type local:BreadcrumbItem}"                       
           TargetType="{x:Type local:BreadcrumbItem}" >

        <!--<Setter Property="Height" Value="20"  />-->
        <Setter Property="HorizontalAlignment" Value="Stretch"  />
        <Setter Property="VerticalAlignment" Value="Stretch"  />
        <Setter Property="FocusVisualStyle" Value="{StaticResource focusVisualStyle}" />

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:BreadcrumbItem}">
                    <Grid Name="MainGrid" SnapsToDevicePixels="True" Margin="0,0"  HorizontalAlignment="Stretch"  >
                        <Separator Visibility="{Binding IsSeparator, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource btv}}" />
                        <Grid Visibility="{Binding IsSeparator, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource fbtvc}}"  >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="0"  />
                            </Grid.ColumnDefinitions>
                            <DockPanel x:Name="basePanel" SnapsToDevicePixels="True" Grid.Column="0" Margin="0" LastChildFill="True" Height="22">
                                <Border DockPanel.Dock="Right" x:Name="borderToggle" BorderThickness="0" Padding="1" BorderBrush="{TemplateBinding BorderBrush}" Background="Transparent"
                                    Visibility="{Binding ShowToggle, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource btv}}" MinWidth="10" >
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition MaxHeight="15"/>
                                            <RowDefinition/>
                                        </Grid.RowDefinitions>
                                        <Rectangle x:Name="borderToggleUpperHighlight" Fill="#75FFFFFF" Visibility="Collapsed"/>
                                        <ToggleButton IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" 
                                              x:Name="buttonExpand" Template="{StaticResource BasicArrowButton}"
                                              MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" VerticalAlignment="Stretch"
                                              KeyboardNavigation.IsTabStop="False" Focusable="False"  Grid.RowSpan="2"
                                              
                                               />
                                        <ToggleButton x:Name="buttonExpander" IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" 
                                              Template="{StaticResource ExpanderArrowButton}" 
                                              MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" VerticalAlignment="Stretch"
                                              KeyboardNavigation.IsTabStop="False" Focusable="False"
                                              Visibility="Collapsed" Grid.RowSpan="2"
                                               />
                                    </Grid>
                                </Border>
                                <Border x:Name="borderCurrent" DockPanel.Dock="Left"  BorderThickness="0" Padding="1"
                                     BorderBrush="{TemplateBinding BorderBrush}" Background="Transparent">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition MaxHeight="15"/>
                                            <RowDefinition/>
                                        </Grid.RowDefinitions>
                                        <Rectangle x:Name="borderCurrentUpperHighlight" Fill="#75FFFFFF" Visibility="Collapsed"/>
                                        <Button x:Name="buttonCurrent"  HorizontalAlignment="Stretch"                                                  
                                                Height="{TemplateBinding ActualHeight}" Template="{StaticResource BaseButton}" 
                                                Grid.RowSpan="2" >
                                            <Button.Content>
                                                <ContentPresenter VerticalAlignment="Stretch" 
                                                    ContentTemplate="{TemplateBinding HeaderTemplate}"  Content="{Binding}" />
                                            </Button.Content>
                                        </Button>
                                    </Grid>
                                </Border>

                            </DockPanel>
                            <Popup IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}" 
                               Placement="Bottom"    PlacementTarget="{Binding ElementName=borderToggle}"
                                       
                                       PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"                                               
                                       AllowsTransparency="True" x:Name="PART_Popup" Margin="1,1,1,1"  Grid.ColumnSpan="2">
                                <Border BorderThickness="1,1,1,1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" 
                                            Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" Name="DropDownBorder">

                                    <Grid>
                                        <ScrollViewer CanContentScroll="True"  HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto"
                                                      Visibility="{Binding Path=IsLoading, Converter={StaticResource fbtvc},
                                                                  Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                                      >
                                            <ItemsPresenter x:Name="itemList" HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                                                     SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"                                                      
                                                     MaxHeight="200" 
                                                     KeyboardNavigation.DirectionalNavigation="None"
                                                     VirtualizingStackPanel.IsVirtualizing="True" 
                                                     VirtualizingStackPanel.VirtualizationMode="Standard"                                                     
                                                    >
                                            </ItemsPresenter>
                                        </ScrollViewer>
                                        <StackPanel Orientation="Horizontal" Visibility="{Binding Path=IsLoading, Converter={StaticResource btv},
                                                Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Top"  >
                                            <ce:SilverLightMain Margin="2" />
                                            <TextBlock Text="Loading..." Margin="2" />
                                        </StackPanel>
                                    </Grid>
                                </Border>
                            </Popup>

                        </Grid>
                    </Grid>
                    <ControlTemplate.Triggers>

                        <EventTrigger RoutedEvent="local:BreadcrumbItem.ShowingCaption"  >
                            <BeginStoryboard>
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="buttonExpand" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame Value="{x:Static Visibility.Visible}" KeyTime="0:0:0.2" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="buttonExpander" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0:0:0.2" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="borderCurrent" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame Value="{x:Static Visibility.Visible}" KeyTime="0:0:0" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <DoubleAnimation Storyboard.TargetName="borderCurrent" FillBehavior="Stop" 
                                                     Storyboard.TargetProperty="MaxWidth" From="0" To="200" Duration="00:00:0.5" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>

                        <EventTrigger RoutedEvent="local:BreadcrumbItem.HidingCaption">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="buttonExpander" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame Value="{x:Static Visibility.Visible}" KeyTime="0:0:0.2" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="buttonExpand" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0:0:0.2" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="borderCurrent" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0:0:0.5" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <DoubleAnimation Storyboard.TargetName="borderCurrent" FillBehavior="Stop" 
                                                     Storyboard.TargetProperty="MaxWidth" From="200" To="0" Duration="00:00:0.5" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>

                        <Trigger Property="IsShadowItem" Value="True">
                            <Setter TargetName="buttonCurrent" Property="Foreground" Value="Silver"/>
                            <Setter TargetName="buttonExpand" Property="Foreground" Value="Silver"/>
                            <Setter TargetName="buttonExpander" Property="Foreground" Value="Silver"/>
                        </Trigger>

                        <Trigger Property="ItemsControl.HasItems" Value="False">
                            <Setter TargetName="DropDownBorder" Property="FrameworkElement.Height" Value="95"/>
                        </Trigger>

                        <!-- Default, without a border between borderCurrent/borderToggle -->
                        <MultiTrigger >
                            <MultiTrigger.Conditions>
                                <Condition Property="IsTopLevel" Value="True" />
                                <Condition SourceName="basePanel" Property="IsMouseOver" Value="True" />                                
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="borderToggle" Property="BorderThickness" Value="0,0,1,0" />
                                <Setter TargetName="borderToggle" Property="Padding" Value="1,0,0,0" />
                                <Setter TargetName="borderToggle" Property="BorderBrush" Value="{StaticResource NormalBorderBrush}" />
                                <Setter TargetName="borderToggleUpperHighlight" Property="Visibility" Value="Visible"/>
                            </MultiTrigger.Setters>
                        </MultiTrigger>

                        <MultiTrigger >
                            <MultiTrigger.Conditions>
                                <Condition Property="IsTopLevel" Value="True" />
                                <Condition Property="ShowCaption" Value="False" />
                                <Condition SourceName="basePanel" Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="borderToggle" Property="BorderThickness" Value="1,0,1,0" />
                                <Setter TargetName="borderToggle" Property="Padding" Value="0,1,0,1" />                                
                            </MultiTrigger.Setters>
                        </MultiTrigger>

                        

                        <MultiTrigger >
                            <MultiTrigger.Conditions>
                                <Condition Property="IsTopLevel" Value="True" />
                                <Condition Property="IsItemVisible" Value="True" />                                
                                <Condition SourceName="basePanel" Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="borderCurrent" Property="BorderThickness" Value="1,0,0,0" />
                                <Setter TargetName="borderCurrent" Property="Padding" Value="0,1,1,1" />
                                <Setter TargetName="borderCurrent" Property="BorderBrush" Value="{StaticResource NormalBorderBrush}" />
                                <Setter TargetName="borderCurrentUpperHighlight" Property="Visibility" Value="Visible"/>
                            </MultiTrigger.Setters>
                        </MultiTrigger>

                        <MultiTrigger >
                            <MultiTrigger.Conditions>
                                <Condition Property="IsTopLevel" Value="True" />
                                <Condition Property="ItemsControl.HasItems" Value="False" />                                
                                <Condition SourceName="basePanel" Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="borderCurrent" Property="BorderThickness" Value="1,0,1,0" />
                                <Setter TargetName="borderCurrent" Property="Padding" Value="0,1,0,1" />
                                <Setter TargetName="borderCurrent" Property="BorderBrush" Value="{StaticResource NormalBorderBrush}" />
                                <Setter TargetName="borderCurrentUpperHighlight" Property="Visibility" Value="Visible"/>
                            </MultiTrigger.Setters>
                        </MultiTrigger>


                        <Trigger SourceName="buttonExpand" Property="IsMouseOver" Value="True">
                            <Setter TargetName="basePanel" Property="Background" Value="{StaticResource HotTrackBrush}" />
                            <Setter TargetName="borderCurrent" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                            <Setter TargetName="borderCurrent" Property="BorderThickness" Value="1,0" />
                            <Setter TargetName="borderCurrent" Property="Padding" Value="0,1" />                            
                            <Setter TargetName="borderCurrentUpperHighlight" Property="Visibility" Value="Visible"/>
                        </Trigger>

                       
                        <Trigger SourceName="buttonExpander" Property="IsMouseOver" Value="True">
                            <Setter TargetName="basePanel" Property="Background" Value="{StaticResource HotTrackBrush}" />
                            <Setter TargetName="borderCurrent" Property="BorderThickness" Value="1,0" />
                            <Setter TargetName="borderCurrent" Property="Padding" Value="0" />
                            <Setter TargetName="borderCurrentUpperHighlight" Property="Visibility" Value="Visible"/>
                        </Trigger>

                        <Trigger SourceName="buttonCurrent" Property="IsMouseOver" Value="True">
                            <Setter TargetName="basePanel" Property="Background" Value="{StaticResource HotTrackBrush}" />                            
                            <Setter TargetName="borderCurrent" Property="Background" Value="Transparent" />
                        </Trigger>

                        <Trigger SourceName="buttonCurrent" Property="IsPressed" Value="True">                            
                            <Setter Property="Background" TargetName="basePanel" Value="{StaticResource PressedBrush}" />
                            <Setter Property="Background" TargetName="borderCurrent" Value="{StaticResource PressedBrush}" />                            
                            <Setter Property="BorderBrush" TargetName="buttonExpand" Value="Gray" />
                            <Setter Property="BorderBrush" TargetName="buttonCurrent" Value="Gray" />
                        </Trigger>

                        <!--<Trigger SourceName="buttonExpand" Property="IsChecked" Value="True">
                            <Setter TargetName="borderCurrent" Property="Background" Value="{StaticResource HotTrackBrush}" />    
                        </Trigger>

                        <Trigger SourceName="PART_Popup" Property="IsOpen" Value="True">
                            <Setter TargetName="borderCurrent" Property="BorderThickness" Value="10,0" />
                            <Setter TargetName="borderCurrent" Property="Padding" Value="0" />
                            <Setter Property="BorderBrush" TargetName="buttonExpand" Value="Gray" />
                            <Setter Property="BorderBrush" TargetName="buttonCurrent" Value="Gray" />
                        </Trigger>-->
                        
                        
                        <EventTrigger RoutedEvent="ComboBox.Loaded"  >
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="00:00:0.5" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>


                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
